//
//  RunRecordVC.m
//  timelyRain
//
//  Created by Jiafei Wei on 16/8/26.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "RunRecordVC.h"
#import "MBTUiColor.h"
#import "RunRecordHeader.h"
#import "RunRecordInfo.h"//组里面的
#import "RunRecordGroupInfo.h"//外面的
#import "RunCell.h"
#import "SportLocusVC.h"

#define bgColor @"#1186D6"
@interface RunRecordVC ()<UIGestureRecognizerDelegate,UITableViewDataSource,UITableViewDelegate,RunRecordHeaderDelegate>
{
    NSMutableArray *data1;
}
@property (weak, nonatomic) IBOutlet UITableView *table;
@property (weak, nonatomic) IBOutlet UIView *staus;
@property (weak, nonatomic) IBOutlet UIView *nav;
@property (weak, nonatomic) IBOutlet UIView *left;
@property (weak, nonatomic) IBOutlet UIView *right;
@end

@implementation RunRecordVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden=YES;
    _table.dataSource=self;
    _table.delegate=self;
    [self setViewBG];
    [self backToRunVC];
}
-(void)setViewBG{
    _staus.backgroundColor =[UIColor colorwithHexString:bgColor];
    _nav.backgroundColor =[UIColor colorwithHexString:bgColor];
    _left.backgroundColor =[UIColor colorwithHexString:bgColor];
    _right.backgroundColor =[UIColor colorwithHexString:bgColor];
}

-(void)backToRunVC{
    _left.userInteractionEnabled = YES;
    UITapGestureRecognizer *backTapGest = [[UITapGestureRecognizer alloc] init];
    backTapGest.numberOfTapsRequired = 1;
    backTapGest.delegate = self;
    [_left addGestureRecognizer:backTapGest];
    [backTapGest addTarget:self action:@selector(backTapView:)];
}
- (void)backTapView:(UITapGestureRecognizer *)backTapGest{
    [self.navigationController popViewControllerAnimated:YES];//返回
}

#pragma mark - 数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _grounp.count;
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    RunRecordGroupInfo *group = _grounp[section];
    return group.isExpend?group.runRecordGroup.count : 0;//根据是否是展开的状态决定组的数量
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RunCell *cell =  [RunCell setRunCellWithTableView:tableView];
    RunRecordGroupInfo *group = _grounp[indexPath.section];
    RunRecordInfo *info = group.runRecordGroup[indexPath.row];
    cell.info =info;
    return cell;
}
#pragma mark - 代理的方法//
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    RunRecordHeader *head =[RunRecordHeader headerViewWithTableView:tableView];
    head.delegate=self;
    RunRecordGroupInfo *group = _grounp[section];
    head.data = group;//在这里显示头部的信息
    head.tag = section;
    return head;
}

#pragma mark - headerView的代理方法
- (void)headerViewDidClickedNameView:(RunRecordHeader *)headerView//分组的搞定了啊
{
    NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:headerView.tag];//这个效果最好
    [_table reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];//刷新listview
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1f;
}
//一定要重写该方法
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     SportLocusVC *locus =[[SportLocusVC alloc]init];
    
    RunRecordGroupInfo *group = _grounp[indexPath.section];
   locus.info = group.runRecordGroup[indexPath.row];
    [self.navigationController pushViewController:locus animated:YES];
}
@end
